﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Bot.Application.Dto;
using Bot.Application.Services;
using Microsoft.AspNetCore.Mvc;

namespace Bot.WebAPI.Controllers
{
    [Route("api/v3/chatbot")]
    [ApiController]
    public class QuickRepliesController : ControllerBase
    {

        private readonly IQuickReplyAppService _app;
        public QuickRepliesController(IQuickReplyAppService app)
        {
            this._app = app;
        }

        [HttpGet]
        [Route("quickreplies/{id:Guid}")]
        public ActionResult<QuickReplyDto> Get([FromRoute] Guid id, [FromQuery] string include)
        {
            QuickReplyDto quickReply = _app.Get(id, include);
            return Ok(quickReply);
        }

        [HttpGet]
        [Route("bots/{botId:Guid}/quickreplies")]
        public ActionResult<IEnumerable<QuickReplyDto>> GetList([FromRoute] Guid botId, [FromQuery] string type, [FromQuery] string include)
        {
            IEnumerable<QuickReplyDto> list = _app.GetList(botId, type, include);
            return Ok(list);
        }

        [HttpPut]
        [Route("quickreplies/{id:Guid}")]
        public ActionResult<QuickReplyDto> Put([FromBody] QuickReplyUpdateDto dto)
        {
            QuickReplyDto quickReply = _app.Update(dto);
            return Ok(quickReply);
        }

        [HttpPost]
        [Route("bots/{botId:Guid}/quickreplies")]
        public ActionResult<QuickReplyDto> Post([FromRoute] Guid botId, [FromBody] QuickReplyCreateDto dto)
        {
            QuickReplyDto quickReply = _app.Add(botId, dto);
            return CreatedAtAction(nameof(Get), new { id = quickReply.Id }, quickReply);
        }

        [HttpDelete]
        [Route("quickreplies/{id:Guid}")]
        public ActionResult Delete([FromRoute] Guid id)
        {
            _app.Delete(id);
            return NoContent();
        }
    }
}
